package com.comdo.newup_loan.adapter;

import android.content.Context;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.comdo.newup_loan.R;
import com.comdo.newup_loan.model.CarBrandItem;

import java.util.List;

/**
 * Created by liyuan on 2017/11/10.
 */

public class CarBrandAdapter extends BaseAdapter {
    private LayoutInflater mInflater;
    private List<CarBrandItem> datas;
    //是否是车型，如果是，字体调小
    private int isModel;

    public CarBrandAdapter(Context context, List<CarBrandItem> datas, int isModel) {
        super();
        mInflater = LayoutInflater.from(context);
        this.datas = datas;
        this.isModel=isModel;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = mInflater.inflate(R.layout.item_car_brand, parent,
                    false);
            viewHolder.tv_font = (TextView) convertView
                    .findViewById(R.id.tv_font);
            viewHolder.tv_name = (TextView) convertView
                    .findViewById(R.id.tv_name);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        if (datas.get(position).getIsFont() == 1) {
            viewHolder.tv_font.setVisibility(View.VISIBLE);
            viewHolder.tv_font.setText(datas.get(position).getName());
            viewHolder.tv_name.setText("");
        } else {
            viewHolder.tv_font.setText("");
            viewHolder.tv_font.setVisibility(View.INVISIBLE);
            viewHolder.tv_name.setText(datas.get(position).getName());
        }
        if (isModel == 1){
            viewHolder.tv_name.setTextSize(TypedValue.COMPLEX_UNIT_SP,8);
        }else{
            //viewHolder.tv_name.setTextSize(TypedValue.COMPLEX_UNIT_SP,16);
        }

        return convertView;
    }

    static class ViewHolder {
        TextView tv_font;
        TextView tv_name;
    }
}
